package easy;

import util.PrintUtils;

public class Solution_888 {

    public int[] fairCandySwap(int[] aliceSizes, int[] bobSizes) {
        int sum1 = 0, sum2 = 0;
        boolean[] array = new boolean[100001];
        for (int a : aliceSizes) {
            sum1 += a;
            array[a] = true;
        }
        for (int b : bobSizes) {
            sum2 += b;
        }

        if (sum1 > sum2) {
            int sub = (sum1 - sum2) / 2;
            for (int b : bobSizes) {
                int c = b + sub;
                if (c <= 100000 && array[c]) {
                    return new int[]{c, b};
                }
            }
        } else {
            int sub = (sum2 - sum1) / 2;
            for (int b : bobSizes) {
                int c = b - sub;
                if (c >= 0 && array[c]) {
                    return new int[]{c, b};
                }
            }
        }
        return null;
    }

    public static void main(String[] args) {
        Solution_888 model = new Solution_888();
        PrintUtils.arrayInt(model.fairCandySwap(new int[]{1,1}, new int[]{2, 2}));
        PrintUtils.arrayInt(model.fairCandySwap(new int[]{2}, new int[]{1, 3}));
        PrintUtils.arrayInt(model.fairCandySwap(new int[]{1, 2, 5}, new int[]{2, 4}));
    }
}
